package cn.cloudreal.cbms.budget.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import cn.cloudreal.cbms.budget.dao.BudgetListDao;
import cn.cloudreal.cbms.common.util.PageBean;
import cn.cloudreal.cbms.vo.CostSubTypeBudget;
import cn.cloudreal.cbms.vo.FundBudget;
import cn.cloudreal.cbms.vo.SourcePlanYear2;

/**
 * <p>
 * Title: CBM
 * </p>
 * <p>
 * Description:预算列表Dao层实现类
 * </p>
 * <p>
 * Copyright: Copyright (c) 2012
 * </p>
 * <p>
 * Company:云恒瑞通
 * </p>
 * 
 * @author WangTao
 * @date 2012-07-19
 */
public class BudgetListDaoImpl extends SqlMapClientDaoSupport implements
        BudgetListDao
{
    /** 日志工具类实例 */
    private static final Logger log = Logger.getLogger(BudgetListDaoImpl.class);

    public CostSubTypeBudget getSubTypeBudget(FundBudget fundBudget, String flag)
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter BudgetListDaoImpl getSubTypeBudget() method, return int");
        }

        //
        CostSubTypeBudget costSubTypeBudget = null;
        if ("1".equals(flag))
        {
            // 查询T_CB_FUNDBUDGET
            costSubTypeBudget = (CostSubTypeBudget) getSqlMapClientTemplate().queryForObject("fundBudget.getSubTypeBudget",
                    fundBudget);
        }
        else if ("2".equals(flag))
        {
            // 查询T_CB_SOURCEPLANYEAR
            costSubTypeBudget = (CostSubTypeBudget) getSqlMapClientTemplate().queryForObject("fundBudget.getSubTypeBudget2",
                    fundBudget);
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit BudgetListDaoImpl getSubTypeBudget() method, return int");
        }
        return costSubTypeBudget;
    }

    public List<String> getYearsByCity(String city)
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter BudgetListDaoImpl getYearsByCity() method, return List<String>");
        }

        // 查询
        List<String> years = getSqlMapClientTemplate().queryForList("fundBudget.getYearsByCity",
                city);

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit BudgetListDaoImpl getYearsByCity() method, return List<String>");
        }
        return years;
    }

    public boolean modifyBudget(FundBudget fbParam)
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter BudgetListDaoImpl modifyBudget() method, return boolean");
        }

        //
        boolean bool = false;
        // 修改
        int flag = getSqlMapClientTemplate().update("fundBudget.modifyBudget",
                fbParam);
        //
        if (flag == 1)
        {
            bool = true;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit BudgetListDaoImpl modifyBudget() method, return boolean");
        }
        return bool;
    }

    public int getMediaBudgetCount(SourcePlanYear2 sourcePlanYear)
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter BudgetListDaoImpl getMediaBudgetCount() method, return int");
        }

        int count = (Integer) getSqlMapClientTemplate().queryForObject("fundBudget.getMediaBudgetCount",
                sourcePlanYear);

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit BudgetListDaoImpl getMediaBudgetCount() method, return int");
        }
        return count;
    }

    public List<SourcePlanYear2> getMediaBudgetList(SourcePlanYear2 sourcePlanYear,
            PageBean page)
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter BudgetListDaoImpl getMediaBudgetList() method, return List<SourcePlanYear2>");
        }

        List<SourcePlanYear2> sourcePlanYears = getSqlMapClientTemplate().queryForList("fundBudget.getMediaBudget",
                sourcePlanYear,
                (page.getPageNo() - 1) * page.getPageSize(),
                page.getPageSize());

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit BudgetListDaoImpl getMediaBudgetList() method, return List<SourcePlanYear2>");
        }
        return sourcePlanYears;
    }

    public boolean deleteBudget(SourcePlanYear2 sourcePlanYear, String flag)
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter BudgetListDaoImpl deleteBudget() method, return boolean");
        }

        //
        boolean bool = false;
        // 修改
        int i = getSqlMapClientTemplate().update("fundBudget.deleteBudget",
                sourcePlanYear);
        //
        if (i != 1)
        {
            bool = true;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit BudgetListDaoImpl deleteBudget() method, return boolean");
        }
        return bool;
    }
}
